<!doctype html>
<html lang="">
<head>
  <meta charset="utf-8">
  <meta name="description" content="">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>kangai</title>

  <link rel="apple-touch-icon" href="apple-touch-icon.png">
  <!-- Place favicon.ico in the root directory -->

  <!-- build:css styles/vendor.css -->
  <!-- bower:css -->
  <!-- endbower -->
  <!-- endbuild -->

  <!-- build:css styles/main.css -->
  <link rel="stylesheet" href="lib/layui/css/layui.css">
  <link rel="stylesheet" href="styles/main.css">
  <!-- endbuild -->

</head>
<body class="layui-layout-body login-page">


  <div class="layui-container d-flex align-center layout-middle">
    <div class="flex">
      <img src="images/peitu.png">
    </div>
    <div class="flex">
      <div class="c-login">
        <div class="login-header text-center">
          <img src="images/login-logo.png">
          <p class="h3">智能营养风险筛查系统</p>
        </div>

        <form class="layui-form login-body" >
          <div class="layui-form-item">
            <input type="text" name="userId" placeholder="请输账号" id="userid"  class="layui-input">
          </div>
          <div class="layui-form-item">
            <input type="password" name="password" placeholder="请输密码（6-20个字符）" id="password" class="layui-input">
          </div>
          <label class="layui-form-item c-checkbox">
            <input type="checkbox" id="remberAccount">
            <span class="box"></span>
            保存用户名、密码
          </label>
          <div class="layui-form-item">
            <button class="layui-btn layui-btn-radius layui-btn-fluid" type="button" id="btn-login">立即提交</button>
          </div>
        </form>

      </div>
    </div>
  </div>

<!-- build:js scripts/vendor.js -->
<!-- bower:js -->
<!-- endbower -->
<!-- endbuild -->


  <script src="lib/layui/layui.js" charset="utf-8"></script>
  <script src="scripts/main.js"></script>
<script type="text/javascript">



  layui.use(['jquery', 'httpService', 'httpRouter'], function() {

    var $ = layui.jquery,
      http = layui.httpService;
    httpRouter = layui.httpRouter;

    function getUser(){
      var userid = localStorage.getItem("userid");
      var password = localStorage.getItem("password");
      if (userid) {
        $("#userid").val(userid);
        $("#password").val(password);
        $("#remberAccount").attr("checked",true);
      } else {
        $("#userid").val("");
        $("#password").val("");
        $("#remberAccount").removeAttr("checked");
      }

    }
    getUser()



    $("#btn-login").on("click",function () {
      var params = {
        userId:$("#userid").val(),
        password:$("#password").val()
      }
      http.post(httpRouter.login,params,function (res) {
        if(res.success){
          window.location="./nutritiveriskView.html";
        }else{
          alert(res.actionErrors)
        }

      })
    })
    $("#remberAccount").on("change",function () {
      var userid = $("#userid").val();
      var password = $("#password").val();
      if (userid.trim() != "" && password.trim() != ""){
        if($(this).is(':checked')){
          localStorage.setItem("userid", userid);
          localStorage.setItem("password", password);
        }else{
          localStorage.clear()
        }
      }else{
        $("#remberAccount").removeAttr("checked");
      }
    });
  })
</script>


</body>
</html>

